<?php
/*
+ --------------------------------------------------- +
|  Ineo Article Manager - Version 2.x
|  Copyright 2006-2007, Dan Cryer and William McGann
+ --------------------------------------------------- +

Ineo Article Manager is free software; you can redistribute it and/or modify
it under the terms of version 3 of the GNU General Public License as published by
the Free Software Foundation.

Ineo Article Manager is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Ineo; see the file License.txt.  If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.

*/

class overview_plugin_categories
{
	// ineo core
	var $core;
	// ipsclass
	var $ipsclass;

	// plugin data:
	var $plugin_data = array('tab_title' => 'Categories', 'is_tab' => false, 'tab_order' => 98, 'enabled' => true);

	/**
	* Constructor - Set variables, load libraries, etc.
	*/
	function overview_plugin_categories( &$core )
	{
		// Set variables:
		$this->core     =& $core;
		$this->ipsclass =& $this->core->ipsclass;

		// Set lang-friendly title:
		$this->plugin_data['tab_title'] = $this->ipsclass->lang['ineo_optab_categories'];
		
		// Enabled?
		$this->plugin_data['enabled'] = ($this->ipsclass->vars['ineo_idx_cats']==0) ? false : true;
		
		// Category is tab?
		$this->plugin_data['is_tab'] = ($this->ipsclass->vars['ineo_idx_cats']==2) ? true : false;
	}

	/**
	* Return plugin data to the core 
	*/
	function get_data()
	{
		// Load articles library if not already loaded:
		if( !isset( $this->core->categories ) )
		{
			$this->core->load_library('categories');
		}
		
		$this->catlib =& $this->core->libs['categories'];

		// Load articles library if not already loaded:
		if( !isset( $this->core->templates['categories'] ) )
		{
			$this->core->load_template('categories');
		}
		
		if ( $this->ipsclass->vars['ineo_idx_cats'] != 0 )
		{
			$list = '';
			
			$cats = $this->catlib->load_cats_by_parent(0);
			
			// Loop & build list:
			foreach( $cats as $cat )
			{
				$cat['info']['category_articles'] = $this->catlib->get_article_count($cat);
				$list .= $this->core->templates['categories']->cat_row( $cat['info'] );
			}

			// Output list using main template:
			if( $this->plugin_data['is_tab'] )
			{
				$list = array( 'output' => $list , 'cols' => array('category' => '90%','cats_articles' => '10%') );
				$category_list = $this->core->templates['global']->tab_table($list);
			}
			else
			{
				$category_list = $this->core->templates['categories']->cat_index( $list , $this->ipsclass->lang['ineo_categories'] );
			}

			return $category_list;
		}
		else
		{
			return false;
		}
	}
}

?>